/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.service.order;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.service.BaseService;
import com.neusoft.lohas.modules.ivm.dao.order.OrderDetailItemDao;
import com.neusoft.lohas.modules.ivm.entity.order.OrderDetailItem;

/**
 * 送货单详情Service
 * @author Jackie.Liu
 * @version 2014-12-23
 */
@Component
@Transactional(readOnly = true)
public class orderDetailItemService extends BaseService {

	@Autowired
	private OrderDetailItemDao orderDetailItemDao;
	
	public OrderDetailItem get(String id) {
		return orderDetailItemDao.get(id);
	}
	
	public Page<OrderDetailItem> find(Page<OrderDetailItem> page, OrderDetailItem orderDetailItem) {
		DetachedCriteria dc = orderDetailItemDao.createDetachedCriteria();
		dc.add(Restrictions.eq(OrderDetailItem.FIELD_DEL_FLAG, OrderDetailItem.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return orderDetailItemDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(List<OrderDetailItem> details) {
		orderDetailItemDao.save(details);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		orderDetailItemDao.deleteById(id);
	}

	public List<OrderDetailItem> findDetailsByOrderId(String id) {
		// TODO Auto-generated method stub
		return orderDetailItemDao.findDetailsByOrderId(id);
	}
	
}
